package com.dmap.knowledge.controller.background;

import com.dmap.base.constants.Constant;
import com.dmap.base.vo.BaseVo;
import com.dmap.knowledge.po.Scene;
import com.dmap.knowledge.service.SceneService;
import com.dmap.knowledge.vo.SceneDownListVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Api(value = "场景", description = "background/场景")
@RestController
@RequestMapping(value = "/background/dmap-knowledge-server/v1/scene")
public class SceneController {
    @Resource
    private SceneService sceneService;
    
    @ResponseBody
    @ApiOperation(value = "场景下拉列表", notes = "场景下拉列表")
    @RequestMapping(value = "/dropDown/list", method = RequestMethod.GET)
    public BaseVo selectScene(@RequestParam String lang) {
        BaseVo result = new BaseVo();
        if (lang == null) {
            result.setCode(Constant.RESPONSE_PARAM_ERROR_CODE);
            result.setMsg(Constant.RESPONSE_PARAM_ERROR_MSG);
            return result;
        }
        if (StringUtils.isBlank(lang)) {
            result.setCode(Constant.RESPONSE_PARAM_ERROR_CODE);
            result.setMsg(Constant.RESPONSE_PARAM_ERROR_MSG);
            return result;
        }
        List<SceneDownListVo> sceneDownListVoList = new ArrayList<>();
        List<Scene> sceneList = sceneService.selectSceneDownList(lang);
        sceneList.forEach(scene -> {
            SceneDownListVo sceneDownListVo = new SceneDownListVo(scene);
            sceneDownListVoList.add(sceneDownListVo);
            
        });
        result.setData(sceneDownListVoList);
        return result;
    }
}
